import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'
import Products from '../views/Products.vue'
import About from '../views/About.vue'
import Contact from '../views/Contact.vue'

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    meta: {
      title: '首页 - 深圳市新鹏原电子有限公司'
    }
  },
  {
    path: '/products',
    name: 'Products',
    component: Products,
    meta: {
      title: '产品中心 - 深圳市新鹏原电子有限公司'
    }
  },
  {
    path: '/about',
    name: 'About',
    component: About,
    meta: {
      title: '公司介绍 - 深圳市新鹏原电子有限公司'
    }
  },
  {
    path: '/contact',
    name: 'Contact',
    component: Contact,
    meta: {
      title: '联系我们 - 深圳市新鹏原电子有限公司'
    }
  }
]

const router = createRouter({
  // Replace process.env with import.meta.env for Vite compatibility
  history: createWebHistory(import.meta.env.BASE_URL),
  routes,
  scrollBehavior() {
    return { top: 0 }
  }
})

router.beforeEach((to, from, next) => {
  document.title = to.meta.title || '深圳市新鹏原电子有限公司'
  next()
})

export default router